package com.vrms.app.controller;

import com.vrms.app.aop.SystemControllerLog;
import com.vrms.app.entity.Worker;
import com.vrms.app.service.WorkerService;
import com.vrms.app.tools.CommonResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("worker")

@CrossOrigin
public class WorkerController {
    @Resource
    private WorkerService workerService;

    @GetMapping("/listPage")
    @SystemControllerLog(description = "分页查询护工信息")
    public CommonResult listPage(int page, int size, String username){
        Map<String,Object> map = new HashMap();
        map.put("count",workerService.count(username));
        map.put("data",workerService.listPage(page,size,username));
        return CommonResult.success(map);
    }

    @PostMapping("/save")
    @SystemControllerLog(description = "添加护工")
    public CommonResult save(@RequestBody Worker worker){
        return CommonResult.success(workerService.save(worker));
    }

    @PostMapping("/update")
    @SystemControllerLog(description = "更新护工信息")
    public CommonResult update(@RequestBody Worker worker){
        return CommonResult.success(workerService.update(worker));
    }

    @PostMapping("/remove")
    @SystemControllerLog(description = "根据ID删除护工信息")
    public CommonResult remove(int id){
        return CommonResult.success(workerService.remove(id));
    }

    @PostMapping("/list")
    @SystemControllerLog(description = "查询所有护工信息")
    public CommonResult list(){
        return CommonResult.success(workerService.list());
    }
}
